package com.fp.m7.repository;

import java.util.List;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;

import com.fp.m7.model.Account;
import com.fp.m7.model.Comment;

public interface CommentRepository extends GraphRepository<Comment> {

	@Query(value = "start account=node({0})" + //
			" match account-[:POSTS]->comment" + //
			" return comment" + //
			" order by comment.auditCD desc skip {2} limit {1}", //
			elementClass = Comment.class)
	List<Comment> findUsersLatestComments(Account account, int limit, int skip);

	@Query(value = "start account=node({0})" + //
			" match account-[:POSTS]->comment" + //
			" where (comment.auditCD >= {1}) and (comment.auditCD < {2})" + //
			" return comment" + //
			" order by comment.auditCD", //
			elementClass = Comment.class)
	List<Comment> findUsersCommentsByDate(Account account, long from, long to);

	// TODO
	@Query(value = "start account=node({0})" + //
			" match account-[f:FOLLOWS]->followed-[:POSTS]->comment" + //
			" where (comment.auditCD >= f.auditCD) and (f.auditDD? > comment.auditCD)" + //
			" return comment" + //
			" order by comment.auditCD desc skip {2} limit {1}", //
			elementClass = Comment.class)
	List<Comment> findCommentFeedForUser(Account account, int limit, int skip);

	@Query(value = "start account=node({0})" + //
			" match account-[:POSTS]->comment" + //
			" return comment", //
			elementClass = Comment.class)
	List<Comment> findAllCommentsByUser(Account account);

}